﻿Ext.define('app.prm.project.SummaryShow', {
    extend: 'Ext.panel.Panel',
    border: true,
    laboratoryId: 0,
    startTime: new Date(),
    bodyStyle: 'padding:5px',
    initComponent: function () {
        var me = this;
        me.items = [
            me.getForm(),
            me.getToDoGrid(),
            me.getNextGrid(),
            me.getTextArea()
        ];
        me.callParent();
    },
    getForm: function () {
        var me = this;
        if (!this.form) {
            this.form = new Ext.form.Panel({
                defaultType: 'textfield',
                border: true,
                title: '上海研发中心第一研究室 2016年32周 (2016-8-8 ~ 2016-8-14)',
                fieldDefaults: {
                    labelWidth: 90,
                    labelAlign: "right",
                    margin: 6
                },
                items: [
                    {
                        xtype: 'displayfield',
                        fieldLabel: '研究室成员',
                        name: 'labUserNum',
                        value: ''
                    },
                    {
                        xtype: 'displayfield',
                        fieldLabel: '负载情况',
                        name: 'status'
                    },
                    {
                        xtype: 'container',
                        flex: 1,
                        layout: 'hbox',
                        items: [
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'nowStaffNeed',
                                fieldLabel: '当前(空闲资源)'
                            },
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'twoWeekNeed',
                                fieldLabel: '2周后'
                            },
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'fourWeekNeed',
                                fieldLabel: '4周后'
                            },
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'sixWeekNeed',
                                fieldLabel: '6周后'
                            },
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'eightWeekNeed',
                                fieldLabel: '8周后'
                            }
                        ]
                    },
                    {
                        xtype: 'container',
                        flex: 1,
                        layout: 'hbox',
                        items: [
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'nowIdleNum',
                                fieldLabel: '当前(需要项目)'
                            },
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'twoWeekIdleNum',
                                fieldLabel: '2周后'
                            },
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'fourWeekIdleNum',
                                fieldLabel: '4周后'
                            },
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'sixWeekIdleNum',
                                fieldLabel: '6周后'
                            },
                            {
                                xtype: 'displayfield',
                                flex: 1,
                                name: 'eightWeekIdleNum',
                                fieldLabel: '8周后'
                            }
                        ]
                    }
                ]
            });
        }
        return this.form;
    },
    getToDoGrid: function () {
        if (!this.toDoGrid) {
            this.toDoGrid = new Ext.grid.Panel({
                title: '进行中项目',
                border: true,
                style: 'margin:10px 0 0 0',
                viewConfig: {
                    enableTextSelection: true //可以复制单元格文字
                },
                autoHeight: true,
                forceFit: false,
                columns: [
                       { header: '项目名称', dataIndex: 'projectName' },
                    { header: '项目编号', dataIndex: 'projectNo' },
                    { header: '项目成员', dataIndex: 'team' },
                    {
                        header: '开始日期', dataIndex: 'startDate', renderer: function (value, p, record) {
                            var v = Ext.util.Format.date(value, 'Y-m-d')
                            return v;
                        }
                    },
                    {
                        header: '应完成日期', dataIndex: 'targetDate', renderer: function (value, p, record) {
                            var v = Ext.util.Format.date(value, 'Y-m-d')
                            return v;
                        }
                    },
                    {
                        header: '预计完成日期', dataIndex: 'planDate', renderer: function (value, p, record) {
                            var v = Ext.util.Format.date(value, 'Y-m-d')
                            return v;
                        }
                    },
                    { header: '备注', dataIndex: 'remark' }
                ],
                store: new Ext.data.Store({
                    fields: [
                        'projectName',
                     { name: 'projectNo' },
                     { name: 'team' },
                     { name: 'startDate' },
                     { name: 'targetDate' },
                     { name: 'planDate' }
                    ],
                    data: []
                })
            });
        }
        return this.toDoGrid;
    },
    getNextGrid: function () {
        var me = this;
        if (!this.nextGrid) {
            this.nextGrid = new Ext.grid.Panel({
                title: '下一步工作',
                border: true,
                style: 'margin:10px 0 0 0',
                viewConfig: {
                    enableTextSelection: true //可以复制单元格文字
                },
                autoHeight: true,
                forceFit: false,
                columns: [
                    { header: '项目名称', dataIndex: 'projectName' },
                    { header: '项目编号', dataIndex: 'projectNo' },
                    { header: '项目成员', dataIndex: 'team' },
                    {
                        header: '开始日期', dataIndex: 'startDate', renderer: function (value, p, record) {
                            var v = Ext.util.Format.date(value, 'Y-m-d')
                            return v;
                        }
                    },
                    {
                        header: '应完成日期', dataIndex: 'targetDate', renderer: function (value, p, record) {
                            var v = Ext.util.Format.date(value, 'Y-m-d')
                            return v;
                        }
                    },
                    {
                        header: '预计完成日期', dataIndex: 'planDate', renderer: function (value, p, record) {
                            var v = Ext.util.Format.date(value, 'Y-m-d')
                            return v;
                        }
                    },
                    {
                        header: '实际完成日期', dataIndex: 'actualDate', renderer: function (value, p, record) {
                            var v = Ext.util.Format.date(value, 'Y-m-d')
                            return v;
                        }
                    },
                    { header: '备注', dataIndex: 'remark' }
                ],
                store: new Ext.data.Store({
                    fields: [
                        'projectName',
                     { name: 'projectNo' },
                     { name: 'team' },
                     { name: 'startDate' },
                     { name: 'targetDate' },
                     { name: 'planDate' },
                     { name: 'actualDate' }
                    ],
                    data: []
                })
            });
        }
        return this.nextGrid;
    },
    getTextArea: function () {
        if (!this.textArea) {
            this.textArea = new Ext.Panel({
                border: false
            });
        }
        return this.textArea;
    },
    listeners: {
        afterrender: function (me) {
            //上海研发中心第一研究室 2016年32周 (2016-8-8 ~ 2016-8-14)
            App.AjaxGet('/api/services/app/summary/Get?LaboratoryId=' + me.laboratoryId + "&StartTime=" + me.startTime, function (data) {
                var record = data.result;
                console.log(record);

                var st = Ext.util.Format.date(record.startTime, 'Y-m-d');
                var et = Ext.util.Format.date(record.endTime, 'Y-m-d');
                var str = record.id == 0 ? "(未填写概要)" : '';
                me.getForm().setTitle("<a style='color:red'>" + record.laboratory + str + "</a>");

                if (record.labUserNum > 0) {
                    record.labUserNum = record.labUserNum + "&nbsp;(" + record.labUserNames + ")";
                }
                me.getForm().getForm().setValues(record);
                me.getTextArea().update(record.note);
                me.getToDoGrid().store.loadData(record.toDos);
                if (record.nexts) {
                    me.getNextGrid().store.loadData(record.nexts);
                }
            });
        }
    }
})